package com.oyb.servlet;

import com.oyb.entity.Student;
import com.oyb.service.StudentServies;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/addstudent")
public class addstudentServlet extends HttpServlet {
    private StudentServies studentServies = new StudentServies();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String sex = req.getParameter("sex");
        String cid = req.getParameter("classes_id");

        //将添加的学生信息通过set方法实例化student对象
        Student student = new Student();
        student.setName(name);
        student.setSex(Integer.parseInt(sex));
        student.setCid(Integer.parseInt(cid));
        System.out.println(student);

        int result = studentServies.insertStudent(student);
        if(result>0){
            resp.sendRedirect("stuquerypage");
        }else{
            resp.sendRedirect("addstudent.jsp?status=5");
        }
    }
}
